/**
 * 
 */
package edu.towson.cosc603.coffeemaker;

import static org.junit.Assert.*;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * @author Maddan
 *
 */
public class CoffeeMakerTest extends TestCase{
	private CoffeeMaker cm;
	private Inventory i;
	private Recipe r1;
	private Recipe r2;
	private Recipe r3;
	private Recipe r4;
	private Recipe r5;
	
	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		cm = new CoffeeMaker();
		i = cm.checkInventory();
		//check for recipe 1
		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setPrice(50);
		r1.setAmtCoffee(3);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(0);
		
		r2 = new Recipe();
		r2.setName("Coffee2");
		r2.setPrice(50);
		r2.setAmtCoffee(3);
		r2.setAmtMilk(1);
		r2.setAmtSugar(1);
		r2.setAmtChocolate(0);
	
		r3 = new Recipe();
		r3.setName("Mocha");
		r3.setPrice(60);
		r3.setAmtCoffee(3);
		r3.setAmtMilk(1);
		r3.setAmtSugar(1);
		r3.setAmtChocolate(3);
				
		r4 = new Recipe();
		r4.setName("Frappucino");
		r4.setPrice(60);
		r4.setAmtCoffee(3);
		r4.setAmtMilk(3);
		r4.setAmtSugar(3);
		r4.setAmtChocolate(0);
				
		r5 = new Recipe();
		r5.setName("Spicy Latte Tea");
		r5.setPrice(70);
		r5.setAmtCoffee(3);
		r5.setAmtMilk(2);
		r5.setAmtSugar(2);
		r5.setAmtChocolate(0);
			
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		cm = null;
	}

	/**
	 * Test method for {@link edu.towson.cosc603.coffeemaker.CoffeeMaker#addRecipe(edu.towson.cosc603.coffeemaker.Recipe)}.
	 */
	@Test
	public void testAddRecipe() {
		assertTrue(cm.addRecipe(r1));
	}

	@Test
	public void testAddRecipe2() {
			cm.addRecipe(r1);
			cm.addRecipe(r2);
			cm.addRecipe(r3);
			cm.addRecipe(r5);
			assertFalse(cm.addRecipe(r4));
	}
	/**
	 * Test method for {@link edu.towson.cosc603.coffeemaker.CoffeeMaker#deleteRecipe(edu.towson.cosc603.coffeemaker.Recipe)}.
	 */
	@Test
	public void testDeleteRecipe() {
		cm.addRecipe(r1);
		assertTrue(cm.deleteRecipe(r1));
	}

	/**
	 * Test method for {@link edu.towson.cosc603.coffeemaker.CoffeeMaker#editRecipe(edu.towson.cosc603.coffeemaker.Recipe, edu.towson.cosc603.coffeemaker.Recipe)}.
	 */
	@Test
	public void testEditRecipe() {
		cm.addRecipe(r1);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		newRecipe.setAmtSugar(2);
		assertTrue(cm.editRecipe(r1, newRecipe));
	}

	@Test
	public void testEditRecipe2() {
		cm.addRecipe(r1);
		Recipe newRecipe = new Recipe();
		newRecipe = r2;
		newRecipe.setAmtSugar(2);
		assertFalse(cm.editRecipe(r2, newRecipe));
	}
	
	/**
	 * Test method for {@link edu.towson.cosc603.coffeemaker.CoffeeMaker#addInventory(int, int, int, int)}.
	 */
	@Test
	public void testAddInventory() {
			assertTrue(cm.addInventory(1,2,3,4));
		
	} 
	@Test
	public void testAddInventory2() {
		assertFalse(cm.addInventory(-1,-2,-3,-4));
		
	}	
	/**
	 * Test method for {@link edu.towson.cosc603.coffeemaker.CoffeeMaker#checkInventory()}.
	 */
	@Test
	public void testCheckInventory() {
		assertEquals(i,cm.checkInventory());
	}

	/**
	 * Test method for {@link edu.towson.cosc603.coffeemaker.CoffeeMaker#makeCoffee(edu.towson.cosc603.coffeemaker.Recipe, int)}.
	 */
	@Test
	public void testMakeCoffee() {
		cm.addRecipe(r1);
		assertEquals(5,cm.makeCoffee(r1,55));
	}
	

	@Test
	 public void testMakeCoffee2(){
               Inventory testInventory = new Inventory();
               testInventory.setCoffee(10);
               testInventory.setMilk(10);
               testInventory.setSugar(10);
               testInventory.setChocolate(10);
               Recipe testRecipe2 = new Recipe();
               
               testRecipe2.setAmtCoffee(20);
               testRecipe2.setAmtMilk(20);
               testRecipe2.setAmtSugar(20);
               testRecipe2.setAmtChocolate(20);
               boolean result = testInventory.enoughIngredients(testRecipe2);
               cm.makeCoffee(testRecipe2, 2);
               assertFalse(result);
               
       }
	/**
	 * Test method for {@link edu.towson.cosc603.coffeemaker.CoffeeMaker#getRecipes()}.
	 */
	@Test
	public void testGetRecipes() {
		cm.addRecipe(r1);
		assertEquals(r1,cm.getRecipeForName("Coffee"));
	}

	/**
	 * Test method for {@link edu.towson.cosc603.coffeemaker.CoffeeMaker#getRecipeForName(java.lang.String)}.
	 */
	@Test
	public void testGetRecipeForName() {
		cm.addRecipe(r1);
		assertEquals(r1,cm.getRecipeForName("Coffee"));
	}
}
